package com.zpself.redis;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2021/4/6 17:55
 * @Modified By
 */
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Resource
    public RedisTemplate<String, String> redisTemplate;

    @RequestMapping(value = "/set",method = RequestMethod.GET)
    public Object hi(String key,String value){
        ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key,value);
        return "ok";
    }

    //redisTemplate.delete(key);y有返回值，可用于api幂等的判断
    @RequestMapping(value = "/del",method = RequestMethod.GET)
    public Object del(String key,String value){
        return redisTemplate.delete(key);
    }
}
